--[[
R级装备难1~2的毕业装备
难2开启词条自由洗练
]]

local item_class = require 'types.item'

local excel = {}
for _,data in ipairs(load_excel('符文装备.xlsx','2级装备')) do
    local name = data.name
    local level = data.lv
    if name and level==6 then
        local data = table.copy(data)
        local state = {}
        
        for a=1,3 do
            local key = data['属性'..a]
            local num = data['数值'..a]
            if key and num then
                state[#state + 1] = {key,num}
                
                --血量和攻击
                if num>1000 then
                    state[#state + 1] = {'基础攻击',num*0.5}
                end
                if key=='技能暴击' then
                    num = num * 0.4
                end
                if key=='普攻暴击' then
                    num = num * 0.4
                end
            end
        end
        data.base_tip = atts_tip2(state)
        data.used_flag = false
        data.state = state
        data.abi_tip = ''
        data.item_class = '符文装备'
        data.tip = [['abi_tip'属性：|n'base_tip'|n'xl_tip''ex_tip']]
        data['随机词条'] = 2
        
        data.ex_tip = function(self)
            local player = self.owner_player or ac.player.self
            return ('所属玩家：%s|n|cff999999装备绑定玩家，可以租用|r'):format(player:get_name())
        end


        ac.lni('item',name,data)
        ac.item(name)

        excel[#excel + 1] = data
    end
end

--[获取随机R级物品名]
function random_item_R()
    local data = table.random(excel)
    return data.name
end

local list = {
    '攻击速度','冷却速度',
    '物理伤害','魔法伤害',
    '普攻输出','技能输出',
    '物理穿透','法术穿透',
    '普攻暴击','技能暴击',
}
local map1 = {}
local map2 = {}
for a,key in ipairs(list) do
    map1[key] = a
end
for a,key1 in ipairs(list) do
    for b=a+1,#list do
        local key2 = list[b]
        local index1 = (map1[key1]*100 + map1[key2])
        local index2 = (map1[key1] + map1[key2]*100)
        map2[index1] = {key1,key2}
        map2[index2] = {key1,key2}
    end
end

for _,data in ipairs(excel) do
    local key1 = data['属性2']
    local key2 = data['属性3']
    if key1 and key2 then
        local index1 = ((map1[key1] or 0)*100 + (map1[key2] or 0))
        local index2 = ((map1[key1] or 0) + (map1[key2] or 0)*100)
        if map2[index1] then
            map2[index1] = nil
            map2[index2] = nil
        else
            print('重复',data.name,key1,key2)
        end
    end
end

for a,da in pairs(map2) do
    print('剩余',da[1],da[2])
end

ac.wait(10,function()
    local test_data1 = {}
    for _,data in ipairs(excel) do
        test_data1[#test_data1 + 1] = ac.item.new(data.name)
    end
    ac.game:notify('测试-注册数据','R级装备',test_data1,function(_,player,name)
        local hero = player.hero
        if hero then
            hero:add_item(name)
        end
    end)


end)